<?php

	/** Classe statique permettant le calcul des catégories
	 * @author Sebastian Mosser
	 */
	 
	 
class Category {

	/** Calcul de la catégorie
	 * @param $birthDate une instance de Date ad'hoc
	 * @param $gender le sexe de l'adhérent
	 */
	public static function display($birthDate,$gender) {
		$years = self::getYears($birthDate);
		if ($gender == Member::$MALE)
			return self::displayMale($years);
		else
			return self::displayFemale($years);
	}
	
	public static function compute($birthDate, $gender) {
		if ($gender == Member::$MALE)
			return self::computeMale(self::getYears($birthDate));
		else
			return self::computeFemale(self::getYears($birthDate));
	
	}
	
	// Renvoi l'age pour la saison en cours 
	private static function getYears($birthDate) {
	
		$birthYear = $birthDate->getYear(); 
		$seasonId = Login::seasonChoosen(False);
		
		if ($seasonId == Season::$NO_SEASON)
			return 0;
		
		$aSeason = Season::read($seasonId);
		$beginDate = $aSeason->getBegin();
		$seasonYear = $beginDate->getYear();
		
		return $seasonYear - $birthYear;
	}
	
	
	/** Catégories masculines **/
	
	public static $maleCat = array(0  => "Inconnue",
																	5  => "Pré-débutant",
																	6  => "Débutant 1",
																	7  => "Débutant 2",
																	8  => "Poussin 1",
																	9  => "Poussin 2",
																	10 => "Benjamin 1",
																	11 => "Benjamin 2",
																	12 => "13 ans 1",
																	13 => "13 ans 2",
																	14 => "15 ans 1",
																	15 => "15 ans 2",
																	16 => "18 ans 1",
																	17 => "18 ans 2",
																	18 => "18 ans 3",
																	19 => "Sénior",
																	35 => "Vétéran" );
	
	private static function displayMale($years) {
		$y = self::computeMale($years);
		return self::$maleCat[$y];
	}
	
	private static function computeMale($years) {
		if ($years < 5 && $years != 0)
			$years = 5;
		if ($years > 19) {
			if ($years < 35)
				$years = 19;
			else
				$years = 35;
		}
		return $years;
	}
	
	/** Catégories Féminines **/
	public static $femaleCat = array(0  => "Inconnue",
																		5  => "Pré-débutante",
																  	6  => "Débutante 1",
																	  7  => "Débutante 2",
																		8  => "Poussine 1",
																		9  => "Poussine 2",
																		10 => "Benjamine 1",
																		11 => "Benjamine 2",
																		12 => "13 ans F 1",
																		13 => "13 ans F 2",
																		14 => "16 ans F 1",
																		15 => "16 ans F 2",
																		16 => "16 ans F 3",
																		17 => "Sénior F",
																		35 => "Vétérante" );
	
	private static function displayFemale($years) {
		return self::$femaleCat[self::computeFemale($years)];
	}
	
	private static function computeFemale($years) {
		if ($years < 5 && $years != 0)
			$years = 5;
		if ($years > 17) {
			if ($years < 35)
				$years = 17;
			else
				$years = 35;
		}
		return $years;
	}
	
	

}


?>